<template>
  <div class="container">
    <div class="header">
      <div class="relative" :style="{height:'6.02rem'}">
        <img v-lazy="pageImgObj.pic01" alt="">
        <span id="share" @click="shareForWechat"  v-html="''">
          <img v-lazy="pageImgObj.pic17" alt="">
        </span>
      </div>
    </div>
    <div class="module" v-for="(list,index) in pageGoodsIdArr" :key="index">
      <div :style="{minHeight:'3.38rem'}"><img v-lazy="pageImgArr[index*2]" alt=""></div>
      <div :style="{minHeight:'3.38rem'}"><img v-lazy="pageImgArr[index*2+1]" alt=""></div>
      <div class="goods-container">
        <div class="wrapper" :style="{'background':list.bgColor}">
          <goods-item :parentData="item" :styleData="itemStyle" @childEvent="goForGoodsDetail" v-for="(item,index) in list.list" :key="index"/>
        </div>
      </div>
    </div>
    <div class="more goods-more">
      <div :style="{minHeight:'0.56rem'}"><img v-lazy="pageImgObj.pic14" alt=""></div>
      <goods-item :parentData="item" :styleData="moreStyle"  @childEvent="goForGoodsDetail"  v-for="(item,index) in moreData.goodsArrList" :key="index"/>
    </div>
  </div>
</template>

<script>
  import GoodsItem from 'components/GoodsItems/lineTwo.vue'
  import MaskModal from 'components/maskDown/index.js'
  import { getGoodsListApi } from "@/apis/publicApi.js";
  export default {
    components:{GoodsItem},
    data(){
      return{
        isMaskLayer:false,//是否分享覆盖
        pageImgArr:[],//静态图片数组
        pageImgObj:{},//静态图片对象
        itemStyle:{width:'3.18rem'},
        moreStyle:{width:'3.38rem'},
        pageGoodsIds:[
          1600977,1613675,1566221,1615827,1592949,1592903,1613315,1615831,1613673,1316783,1613317,1609623,
          1613671,1508999,1613323,1615829,1509029,1613319,1613321,1170855,1509015,1616383,1383069,1615833
        ],
        pageGoodsIdArr:[],
        moreData:{
          reqestIds:'',
          goodsIds:[
            1614193,1614191,1614189,1614187,1614185,1614183,1614181,1614179,1614177,1614175,1614173,1614171,1614169,
            1614167,1614165,1614163,1614215,1614217,1614197,1614195,1614219,1614221,1614223,1614225,1544991,1547257,
            1614281,1614279,1614213,1614211,1614209,1614207,1614205,1614203,1614201,1614199,1614161,1614159,1614833,
            1614835,1614837,1614839,1614841,1614843,1614845,1614847,1614849,1614851,1614825,1614827,1614829,1614831
          ],
          goodsArrList:[]
        },
        requestLock:false,//请求锁用于上啦加载
        pagination:{ pageIndex:0, pageSize:20, totalPage:0 }
      }
    },
    created(){
      if( this.shareJudge('isshare') ){ MaskModal(); }
      this.pagination.totalPage=Math.ceil(this.moreData.goodsIds.length/this.pagination.pageSize);
      this.initMoreParam();
      this.initPageImg();
      this.getGoodsAction();
    },
    mounted(){
      let that=this;
      window.addEventListener('scroll',function(){
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;//已经滚动到上面的页面高度
        let scrollHeight =  Math.max(document.body.scrollHeight,document.body.offsetHeight);//页面高度
        let windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;//浏览器窗口高度
        //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
        if (scrollHeight -scrollTop - windowHeight <= 350 && !that.requestLock) {
          that.requestLock=true;//添加锁定
          that.getMoreGoodsApi(that.moreData.reqestIds);//请求数据
        }
      },false)
    },
    methods:{
      initPageImg(){
        this.pageImgArr=[
          require('../../../assets/img/dressNoteVa/derssNoteVa02.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa03.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa04.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa05.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa06.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa07.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa08.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa09.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa10.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa11.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa12.jpg'),
          require('../../../assets/img/dressNoteVa/derssNoteVa13.jpg')
        ],
        this.pageImgObj={
          pic01:require('../../../assets/img/dressNoteVa/derssNoteVa01.jpg'),
          pic14:require('../../../assets/img/dressNoteVa/derssNoteVa14.jpg'),
          pic17:require('../../../assets/img/derssNote/derssNote17.png')
        }
      },
      goForGoodsDetail(id){
        this.$navtiveUtils.jump2goods(id);
      },
      goForSpecialDetail(id){
        this.$navtiveUtils.jump2special(id);
      },
      getGoodsAction(){
        let param=this.pageGoodsIds.toString();
        getGoodsListApi(param).then(res =>{
          let tempData=[];
          for (let index = 0; index < 6; index++) {
            let item=res.data.slice(index*4,(index+1)*4);
            let bgColor= index % 2 ==0 ? '#F4D5C9' : '#E5E5E5';
            tempData.push({list:item,bgColor:bgColor});
          }
          this.pageGoodsIdArr=tempData;
        });
      },
      initMoreParam(){
        let fromIndex =this.pagination.pageIndex*this.pagination.pageSize;
        let toIndex=(this.pagination.pageIndex+1)*this.pagination.pageSize;
        this.moreData.reqestIds=this.moreData.goodsIds.slice(fromIndex,toIndex).toString();
      },
      async getMoreGoodsApi(list){
        if(list.length==0 || !list){return false}
        await getGoodsListApi(list).then(res =>{
          if(res.code==200 && res.status=='success'){
            this.moreData.goodsArrList=this.moreData.goodsArrList.concat(res.data);
            this.pagination.pageIndex++;
            this.requestLock=false;//解除锁定
            this.initMoreParam();
          }
        });
      },
      shareJudge(e) {
        let temp = window.location.search.replace("?", "").split("&");
        let isFlag = false;
        for (let index = 0; index < temp.length; index++) {
          isFlag += temp[index].split("=").indexOf(e)>-1;
        }
        return isFlag;
      },
      shareForWechat() {
        let that = this;
        let pageTitle=document.title ;
        setTimeout(function() {
          that.$navtiveUtils.share(pageTitle, "潮流精选好货，限时折扣中，快来抢购！","");
        }, 300);
      }
    }
  }
</script>
<style lang="less">
html,body{
  background-image: url('../../../assets/img/dressNoteVa/derssNoteVa15.jpg');
  background-repeat: repeat-y;
  background-size: contain;
}
</style>

<style lang="less" scoped>
.relative{
  position: relative;
  #share{
    width: 1.25rem;
    height: 0.55rem;
    position: absolute;
    top: 0.1rem;right: 0;
  }
}
.module{
  margin: 0 0.3rem;
  .goods-container{
    padding: 0.1rem 0.1rem 0.2rem;
    font-size: 0.3rem;
    background-image: url('../../../assets/img/dressNoteVa/derssNoteVa16.jpg');
    background-repeat: repeat-y;
    background-size: contain;
    .wrapper{
      display: flex;
      flex-wrap: wrap;
      font-family: '微软雅黑';
      padding: 0.1rem;
      .goods:nth-child(2n){
        margin-right: 0
      }
    }
  }
}

.more {
  padding-bottom: 0.1rem;
  &.goods-more{
    display: flex;
    flex-wrap: wrap;
    margin: 0 0.3rem;
    .goods:nth-child(2n+1){margin-right: 0}
  }
  .special {position: relative;}
  .info-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 0.6rem;
    padding: 0 0.3rem;
    line-height: 0.6rem;
    color: #666;
    font-size: 0.28rem;
    position: absolute;
    bottom: 0;
    left: 0;
    background: #fff;
    box-sizing: border-box;
    .title {
      width: 55%;
      height: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .date {
      width: 30%;
      height: 100%;
      text-align: right;
    }
  }
}
</style>